package com.stlm2.controller.commission;

import com.stlm2.core.common.page.PageView;
import com.stlm2.dems.entity.Commission;
import com.stlm2.dems.service.CommissionService;
import com.stlm2.dems.dao.UserDao;
import com.stlm2.dems.entity.User;
import com.stlm2.util.codecontent.CodeContent;
import org.apache.commons.lang.math.NumberUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Author：fuchunyu
 * Date：2017/9/13
 * Description：
 */
@Controller
@RequestMapping("/commissionC")
public class CommissionController {

    @Resource
    private UserDao userDao;
    @Resource
    private CommissionService commissionService;

    @ResponseBody
    @RequestMapping(value = "/getCommission.json",produces="application/json;charset=UTF-8")
    public String getCommission(String companyCode,String token,String page){
        User user =userDao.getByToken(token);
        if(user==null)
            return CodeContent.returnLogin();

        int pageNo = 1;
        int pageSize=20;
        if (NumberUtils.isDigits(page) && !"0".equals(page.trim())) {
            pageNo = NumberUtils.toInt(page);
        }
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("upperUserId",user.getId());
        PageView pageView=commissionService.getpage2(pageNo,pageSize,"queryList",map);

        Map<String,Object> result=new HashMap<String,Object>();
        result.put("data",commissionService.convent(pageView.getRecords()));
        result.put("recordsTotal", pageView.getRowCount());
        result.put("totalPage", pageView.getPageCount());
        return CodeContent.returnSuccess(result);
    }
    @ResponseBody
    @RequestMapping(value = "/getDetailCommission.json",produces="application/json;charset=UTF-8")
    public String getDetailCommission(String companyCode,String code){
        List<Commission> list=commissionService.getbyCode(code);
        return CodeContent.returnSuccess(commissionService.conventDetail(list));
    }
}
